﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Autenticazione.DB;
using Autenticazione.Tools;

namespace Autenticazione.BusinessObject
{
    public class Utente
    {
        public string EMail;
        public string Password;

        public Utente()
        {
        }

        public Utente(string email, string password)
        {
            this.EMail = email;
            this.Password = password;
        }

        public bool UtenteEsistente()
        {
            string strSQL = string.Format(@"select count(*) from Utente where Email = '{0}'", this.EMail);
            DB.DB db = new DB.DB();

            return (db.ExecuteScalar(strSQL) > 0);
        }

        public bool VerificaUtente()
        {
            string strSQL = string.Format(@"select count(*) from Utente where Email = '{0}' and Password = '{1}'", this.EMail, Tools.Tools.CryptText(this.Password));
            DB.DB db = new DB.DB();

            return (db.ExecuteScalar(strSQL) > 0);
        }

        public Boolean Salva()
        {
            string strSQL = string.Format(@"insert into Utente values ('{0}','{1}')", this.EMail, Tools.Tools.CryptText(this.Password));
            DB.DB db = new DB.DB();
            Boolean saved = db.ExecuteNonQuery(strSQL);
            
            return saved;
        }
    }
}